package com.ohos.connect.devicecloud.app.modular.user.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.ohos.connect.devicecloud.app.modular.user.model.dto.*;
import com.ohos.connect.devicecloud.app.modular.user.model.vo.AppUserInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ohos.connect.devicecloud.app.modular.user.model.entity.AppUser;
import com.ohos.connect.devicecloud.app.modular.user.service.AppUserService;
import com.ohos.connect.devicecloud.common.annotation.CommonLog;
import com.ohos.connect.devicecloud.common.pojo.CommonResult;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * APP用户控制器
 **/
@Api(tags = "APP用户接口")
@ApiSupport(author = "OHOS_CONNECT_TEAM", order = 4)
@RestController()
@RequestMapping(value = "/api/v1/device_cloud/app/user")
@Validated
public class AppUserController {

    @Resource
    private AppUserService appUserService;

    /**
     * 获取APP用户分页
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "获取APP用户分页", hidden = true)
    @GetMapping("/page")
    public CommonResult<Page<AppUser>> page(AppUserPageDTO appUserPageDTO) {
        return CommonResult.data(appUserService.page(appUserPageDTO));
    }

    /**
     * 注册APP用户
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation("注册APP用户")
    @CommonLog("注册APP用户")
    @PostMapping("/add")
    public CommonResult<Boolean> add(@RequestBody @Valid AppUserInsertDTO appUserInsertDTO) {
        return CommonResult.data(appUserService.insert(appUserInsertDTO));
    }

    /**
     * 编辑APP用户
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation("编辑APP用户")
    @CommonLog("编辑APP用户")
    @PostMapping("/edit")
    public CommonResult<Boolean> edit(@RequestBody @Valid AppUserEditDTO appUserEditDTO) {
        return CommonResult.data(appUserService.edit(appUserEditDTO));
    }

    /**
     * APP账户绑定邮箱
     * 
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation("APP账户绑定邮箱")
    @CommonLog("APP账户绑定邮箱")
    @PostMapping("/email")
    public CommonResult<Boolean> bindEmail(@RequestBody @Valid AppUserEmailDTO appUserEmailDTO) {
        return CommonResult.data(appUserService.bindEmail(appUserEmailDTO));
    }

    /**
     * 删除APP用户
     */
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "注销APP用户")
    @CommonLog("注销APP用户")
    @PostMapping("/delete")
    public CommonResult<Boolean> delete(@RequestBody @Valid AppUserDeleteDTO appUserDeleteDTO) {
        return CommonResult.data(appUserService.deleteByAccount(appUserDeleteDTO.getAccount()));
    }

    /**
     * 根据id获取APP用户详情
     */
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "根据账号获取APP用户详情")
    @GetMapping("/detail")
    public CommonResult<AppUserInfoVO> detail(@Valid AppUserAccountDTO appUserAccountDTO) {
        return CommonResult.data(appUserService.detail(appUserAccountDTO));
    }

    /**
     * 根据phone获取APP用户详情
     */
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "根据手机号获取APP用户详情",hidden = true)
    @GetMapping("/detail/phone")
    public CommonResult<AppUserInfoVO> detail(@Valid AppUserPhoneDTO appUserPhoneDTO) {
        return CommonResult.data(appUserService.detailByPhone(appUserPhoneDTO));
    }

}
